#include "Monster.h"
#include "Player.h"
#include "EntityManager.h"
#include <stdint.h>
#include <sstream>
#include <iostream>
#include <stdio.h>


extern EntityManager* gEntityMgr;

static uint32_t g_value;
extern int glob_val;

std::vector<std::string> gTestVec;
//struct OperatorTest
//{
//public:
//	int a;
//	void operator()()
//	{
//		//static std::vector<int> vec;
//		//vec.push_back(3);
//		//std::cout << "OperatorTest ---  tttt:" << vec.size()  << std::endl;
//
//		for (EntityList::const_iterator itr = gEntityMgr->entity_list_.begin();
//			itr != gEntityMgr->entity_list_.end(); ++itr)
//		{
//			std::cout << "-----" << (*itr)->GetVirtualName() << "-----" << std::endl << std::endl << std::endl;
//		}
//	}
//};

std::string Monster::GetVirtualName()
{
    std::stringstream ret;
    ret << "Virtual Monster Test " << g_value++;

    static bool is_first = false;
    if (!is_first)
    {
        //gEntityMgr->setStaticValue(1000);
        is_first = true;
	    Singleton::getInstance().getValue() = 100000;
        glob_val = 777;
        g_static_val = 888;
        //int * const_ptr = const_cast<int*>(&CONST_VAL);
        //int * const_ptr = const_cast<int*>(&MyNS::CONST_VAL);
        //*const_ptr = 20000;
        gEntityMgr->modifyConstVal();
    }
    std::cout << &(gEntityMgr->getStaticValue()) << std::endl;
	return ret.str();
}


std::string Player::GetVirtualName()
{
	return "Virtual Player Test";
}

//OperatorTest test_fun;

unsigned int EntityManager::GetStaticValue()
{
    static char ch = 'a';
    //return ++ch;
    ch += 1;
    std::string str;
    str.append(1, ch);
    gTestVec.push_back(str);
    return 10;
}

void EntityManager::modifyConstVal()
{
    int * const_ptr = const_cast<int*>(&class_const_val);
    *const_ptr = 20000;
    //const_ptr = const_cast<int*>(&(gEntityMgr->getStaticValue()));
    //*const_ptr = 1000;
}

void EntityManager::PrintEntityListInfo(std::string str, int a)
{
	for (EntityList::const_iterator itr = entity_list_.begin();
		itr != entity_list_.end(); ++itr)
	{
		std::cout << (*itr)->GetVirtualName() << std::endl;
	}
	std::cout << "replace index4:" << a << " static: " << GetStaticValue() << "-" << GetFunctionValue()  << std::endl
		<< std::endl << std::endl;

	AddFuntiocnTest();


	getClassName();

	/*test_fun();*/
    for (std::vector<std::string>::const_iterator it = gTestVec.begin(); it != gTestVec.end(); ++it ) {
        printf("------------------------ %s\n", it->c_str());
    }
}

std::vector<int> vec;

void EntityManager::AddFuntiocnTest()
{
	vec.push_back(3);
	std::cout << "AddFuntiocnTest-" << vec.size()  << std::endl;

}




struct MyStruct
{
public:
	MyStruct()
	{
		gEntityMgr->AddEntityPrivate(new Player);
	}
};

MyStruct st;



//std::string EntityManager::getClassName()
//{
//	std::cout << " ClassName EntityManager ----!!" << std::endl;
//	return "EntityManager";
//}




//
//void test()
//{
//	OperatorTest test_fun;
//	test_fun();
//}




int getTestValueXcy()
{
    static int c = 1000000;
    return ++c;
}
